local zaisu = fk.CreateSkill {
  name = "th_zaisu",
  tags = { Skill.Wake }
}

zaisu:addEffect(fk.TurnEnd, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(zaisu.name) and
      player:usedSkillTimes(zaisu.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    local room = player.room
    local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
    if turn_event == nil then return end
    local n = 0
    room.logic:getActualDamageEvents(1, function (e)
      local damage = e.data
      if damage.from then
        n = n + damage.damage
      end
    end, Player.HistoryTurn)
    return n >= #room:getAlivePlayers(false)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    if player.dead then return end
    if player:isWounded() then
      room:recover{
        who = player,
        num = player.maxHp - player.hp,
        skillName = zaisu.name,
        recoverBy = player
      }
    end
    room:handleAddLoseSkills(player, "th_heju")
  end
})

Fk:loadTranslationTable{
  ["th_zaisu"] = "再塑",
  [":th_zaisu"] = "觉醒技，每回合结束时，若本回合全场造成的伤害值不小于场上角色数，你减1点体力上限、回复至体力上限并获得〖合局〗。",
}

return zaisu